package cn.wolfcode.service.Impl;

import cn.wolfcode.domain.Activity;
import cn.wolfcode.domain.ActivityItem;
import cn.wolfcode.domain.Choice;
import cn.wolfcode.mapper.ActivityItemMapper;
import cn.wolfcode.mapper.ActivityMapper;
import cn.wolfcode.mapper.ChoiceMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IActivityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ActivityServiceImpl implements IActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Autowired
    private ChoiceMapper choiceMapper;

    @Autowired
    private ActivityItemMapper activityItemMapper;


    @Override
    public void save(Activity activity) {
        activityMapper.insert(activity);
    }

    @Override
    public void delete(Long id) {
        activityMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Activity activity) {
        activityMapper.updateByPrimaryKey(activity);
    }

    @Override
    public Activity get(Long id) {
        return activityMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Activity> listAll() {
        return activityMapper.selectAll();
    }

    @Override
    public PageInfo<Activity> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<Activity> activitys = activityMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<Activity>(activitys);
    }

    @Override
    public List<ActivityItem> selectByAid(Long id) {
        return activityItemMapper.selectByAid(id);
    }

    @Override
    public Choice selectByempIdAndAid(Long empId, Long Aid) {
        Choice choice = choiceMapper.selectByempIdAndAid(empId, Aid);
        return choice;
    }

    @Override
    public void insertChoice(Long empId, Long activityItemId) {
        choiceMapper.insertChoice(empId,activityItemId);
    }

    @Override
    public ActivityItem getActivityItem(Long activityItemId) {
        ActivityItem activityItem = activityItemMapper.getActivityItem(activityItemId);
        return activityItem;
    }

    @Override
    public void updateActivityItem(ActivityItem activityItem) {
        activityItemMapper.updateActivityItem(activityItem);
    }
}
